package com.yami.shop.common.storage;

import com.yami.shop.common.bean.AliOss;
import com.yami.shop.common.bean.Qiniu;
import com.yami.shop.common.config.ShopBasicConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author mengcy 2020-06-20
 */
@Configuration
public class StorageConfig {

    @Autowired
    Qiniu qiniu;

    @Autowired
    AliOss aliOss;

    @Autowired
    ShopBasicConfig basicConfig;

    @Bean
    public IStorage storage(){
        String type = basicConfig.getStorage();
        if(type.equals("alioss")){
            return new AliOssStorage(aliOss);
        }else if(type.equals("qiniu")){
            return new QiniuStorage(qiniu);
        }else {
            return null;
        }
    }
}
